<?php
/**
 * 广告图控制器
 * User: lan
 * Date: 2018/1/12
 * Time: 20:17
 */
namespace app\yunda\admin;

use app\common\builder\ZBuilder;
use think\Db;
/****
 * ssda
 */
class Tongji extends Base
{
    public function month(){//月度统计
        $body=request()->only('_filter_time_to');
        if(!empty($body)){
            if(empty($body['_filter_time_to'])) $this->error('月份不能为空');
            $time=$body['_filter_time_to'];
            $time = strtotime($time.'-01');
        }else{
            $time = time();
        }
        $year = date('Y',$time);
        $month = date('m',$time);
        $days =date('t',strtotime($month.'-'.$year));
        $member = array();
        $order = array();
        $xAxis = array();
        for($i=1;$i<$days;$i++){
            $start_time = strtotime($year.'-'.$month.'-'.$i);
            $end_time = $start_time + 86399;
//            $start_time=date('Y-m-d H:i:s',$start_time);
//            $end_time=date('Y-m-d H:i:s',$end_time);
            $member[] = Db::table('dp_yd_order')
                ->where(array('create_time'=>array('between',array($start_time,$end_time))))->count();
            $xAxis[] = $i;
        }
//        dump(implode(',', $member));die;
        $this->assign('member',implode(',', $member));
//        $this->assign('order',implode(',', $order));
        $this->assign('xAxis',implode(',', $xAxis));
        $this->assign('time',$time);
        $this->assign('title',"{$year}年{$month}月的数据统计");
        $this->assign('zhi',1);
        return ZBuilder::make('table')
            ->setTemplate('month')
            ->fetch();
    }

    public function years(){
        $body=request()->only('_filter_time_to');
        if(!empty($body)){
            if(empty($body['_filter_time_to'])) $this->error('年份不能为空');
            $time=$body['_filter_time_to'];
            $time = strtotime($time.'-01'.'-01');
        }else{
            $time = time();
        }
        $year = date('Y',$time);
        $month = date('m',$time);
        $member = array();
        $order = array();
        $xAxis = array();
        for($i=1;$i<=12;$i++){
            $start_time=strtotime($year.'-'.$i.'-'.'01');
            $days =date('t',strtotime($year.'-'.$i));
            $end_time = $start_time + 24*3600*$days-1;
//            $start_time=date('Y-m-d H:i:s',$start_time);
//            $end_time=date('Y-m-d H:i:s',$end_time);
            $member[] =Db::table('dp_yd_order')->where(array('create_time'=>array('between',array($start_time,$end_time))))->count();
            $xAxis[] = $i;
        }
        $this->assign('member',implode(',', $member));
        $this->assign('xAxis',implode(',', $xAxis));
        $this->assign('time',$time);
        $this->assign('title',"{$year}年的数据统计");
        $this->assign('zhi',2);
        return ZBuilder::make('table')
            ->setTemplate('years')
            ->fetch();
    }
}